<template>
	<view class="page">
		<view style="width: 100%;height: 25rpx;"></view>
		<view class="search-bar">
			<uni-icons type="search" size="20"></uni-icons>
			<input type="text" placeholder="搜索门店名称" v-model="searchText" />
		</view>
		<scroll-view scroll-y="true" class="printer-list" @scrolltolower="loadMore">
			<view class="printer-item" v-for="(item, index) in filteredPrinters" :key="index"
				@tap="goAddClerk(item.id)">
				<view class="">
					<view class="printer-name">{{ item.store_name }}</view>
					<view class="store-name">电话：{{item.mobile}}</view>
				</view>
				<uni-icons type="arrowright" size="20"></uni-icons>
			</view>
		</scroll-view>
		<view class="empty" v-if="isEmpty">
			<image src="/static/empty-icon.png" mode="widthFix"></image>
			<text>暂无数据，如有问题，请联系客服</text>
		</view>
	</view>
</template>

<script>
	import {
		storesList
	} from "@/api/userApi/user.js"
	export default {
		data() {
			return {
				searchText: '',
				storeList: [],
				isEmpty: false,
				params: {
					page: 1,
					page_size: 500,
				},
			}
		},
		methods: {
			getStoresList() {
				storesList(this.params).then(res => {
					if (res.code == 200) {
						if (res.data.list.length == 0) {
							this.isEmpty = true
						} else {
							this.isEmpty = false
						}

						this.storeList = res.data.list
					}
				})
			},
			goAddClerk(id) {
				uni.navigateTo({
					url: `/pagesUser/addClerk/addClerk?id=${id}`
				})
			}
		},
		computed: {
			filteredPrinters() {
				if (this.searchText) {
					return this.storeList.filter(printer => printer.store_name.includes(this.searchText));
				}
				return this.storeList;
			}
		},
		onLoad() {
			this.getStoresList()
		}
	}
</script>

<style lang="scss">
	.page {
		background-color: #f5f5f5;
		height: 100vh;
		position: relative;

		.search-bar {
			height: 70rpx;
			background-color: #fff;
			border-radius: 40rpx;
			display: flex;
			align-items: center;
			padding: 0 20rpx;
			margin: 0 20rpx;
			position: static;
			top: 10rpx;

			uni-icons {
				margin-right: 10rpx;
			}

			input {
				flex: 1;
				height: 60rpx;
				border: none;
				font-size: 32rpx;
			}
		}

		.printer-list {
			width: 95%;
			padding: 20rpx;
			margin-top: 15rpx;

			.printer-item {
				height: 120rpx;
				background-color: #fff;
				border-radius: 9rpx;
				box-shadow: 0rpx 0rpx 15rpx 0rpx rgba(0, 0, 0, 0.08);
				margin-bottom: 32rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 0 20rpx;

				.printer-name {
					font-weight: 400;
					font-size: 29rpx;
					color: #333333;
				}

				.store-name {
					font-weight: 400;
					font-size: 25rpx;
					color: #666666;
					margin-top: 10rpx;
				}
			}
		}

		.empty {
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			position: absolute;
			top: 50%;
			left: 50%;
			transform: translate(-50%, -50%);

			image {
				width: 200rpx;
				margin-bottom: 20rpx;
			}

			text {
				font-size: 24rpx;
			}
		}
	}
</style>